package com.johngene.mapapp;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class HomeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_home);

        EditText editText= findViewById(R.id.position);
        Button button = findViewById(R.id.start_fack);
        Button button2 = findViewById(R.id.start_fack2);
        Button button2_1 = findViewById(R.id.start_fack2_1);
        Button button3 = findViewById(R.id.start_fack3);
        Button button4 = findViewById(R.id.start_fack4);
        Button button5 = findViewById(R.id.stop_fack);
        Button gpsBtn = findViewById(R.id.gps_btn);

        button.setOnClickListener(v -> {
            String inputText = editText.getText().toString();
            Intent intent = new Intent(this, ServiceGo.class);
            //stopService(intent);
            intent.putExtra("data", inputText);
            startService(intent);
            Toast.makeText(getApplicationContext(), "操作成功", Toast.LENGTH_SHORT).show();
        });
        //平湖位置
        button2.setOnClickListener(v -> {
            editText.setText("121.236822,30.678111");
            String inputText = editText.getText().toString();
            Intent intent = new Intent(this, ServiceGo.class);
            //stopService(intent);
            intent.putExtra("data", inputText);
            startService(intent);
            Toast.makeText(getApplicationContext(), "操作成功", Toast.LENGTH_SHORT).show();
        });
        //嘉兴位置
        button2_1.setOnClickListener(v -> {
            editText.setText("120.89121775642067,30.733993435254135");
            String inputText = editText.getText().toString();
            Intent intent = new Intent(this, ServiceGo.class);
            //stopService(intent);
            intent.putExtra("data", inputText);
            startService(intent);
            Toast.makeText(getApplicationContext(), "操作成功", Toast.LENGTH_SHORT).show();
        });
        //连云港石化位置
        button3.setOnClickListener(v -> {
            editText.setText("119.615552,34.521443");
            String inputText = editText.getText().toString();
            Intent intent = new Intent(this, ServiceGo.class);
            //stopService(intent);
            intent.putExtra("data", inputText);
            startService(intent);
            Toast.makeText(getApplicationContext(), "操作成功", Toast.LENGTH_SHORT).show();
        });
        //科创城位置
        button4.setOnClickListener(v -> {
            editText.setText("119.225042,34.605536");
            String inputText = editText.getText().toString();
            Intent intent = new Intent(this, ServiceGo.class);
            //stopService(intent);
            intent.putExtra("data", inputText);
            startService(intent);
            Toast.makeText(getApplicationContext(), "操作成功", Toast.LENGTH_SHORT).show();
        });
        //停止模拟
        button5.setOnClickListener(v -> {
            editText.setText("");
            Intent intent = new Intent(this, ServiceGo.class);
            stopService(intent);
            Toast.makeText(getApplicationContext(), "操作成功", Toast.LENGTH_SHORT).show();
        });
        //跳转地图选点
        gpsBtn.setOnClickListener(v -> {
            // 在MainActivity中
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
        });

        //stopService(intent);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
    }
}